package imvu.rbox.object
{
	import anshe.object.ExTextField;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import imvu.rbox.struct.CGamePlayerInfo;

	public class MyInfoObject extends Sprite
	{
		public var txtUserName:ExTextField;	//	用户名显示区
		public var mcUFacePlace:MovieClip;	//	用户头像显示区块
		public var txtScore:ExTextField;	//	当前总计得分
		public var txtSpeed:ExTextField;	//	当前速度
		public var txtLine:ExTextField;		//	当前已经清除的行
		
		private var userInfo:CGamePlayerInfo;	//	当前玩家的信息
		private var fLoader:UserFaceLoader;		//	用户头像下载对象
		
		public function MyInfoObject()
		{
			this.txtUserName.size = 10;
			this.txtScore.size = 10;
			this.txtLine.size = 10;
			this.txtSpeed.size = 10;
			
			this.score = 0;
			this.speed = 0;
			this.line = 0;
			this.userName = "";
			
			this.mcUFacePlace.gotoAndStop(1);
			
			fLoader = new UserFaceLoader(this.mcUFacePlace.width, this.mcUFacePlace.height);
			fLoader.x = this.mcUFacePlace.x;
			fLoader.y = this.mcUFacePlace.y;
			this.addChild(fLoader);
		}
		
		public function set info(uInfo:CGamePlayerInfo):void
		{
			try
			{
				this.userInfo = uInfo;
				
				if(uInfo)
				{
					this.userName = this.userInfo.userNick;
					this.score = this.userInfo.userScore;
					this.line = this.userInfo.cleanLines;
					this.speed = this.userInfo.gameSpeed;
					
					if(this.userInfo.isGirl)
					{
						this.mcUFacePlace.gotoAndStop(2);
					}
					else
					{
						this.mcUFacePlace.gotoAndStop(3);
					}
					
					this.fLoader.LoadFace(this.userInfo.userFace);
				}
				else
				{
					this.userName = "";
					this.score = 0;
					this.line = 0;
					this.speed = 0;
					this.mcUFacePlace.gotoAndStop(1);
					this.mcUFacePlace.mouseChildren = this.mcUFacePlace.mouseEnabled = false;
					this.fLoader.RemoveFace();					
				}
			}
			catch(e:*)
			{
				trace("初始化 myInfo 时出错 ");
			}
		}
		
		//	取得当前用户的信息
		public function get info():CGamePlayerInfo
		{
			return this.userInfo;
		}
		
		public function set userName(str:String):void
		{
			this.txtUserName.text = str;
		}
		
		public function set score(num:Number):void
		{
			num = (num < 0) ? 0 : num;
			this.txtScore.text = "Score:" + num;
		}
		
		public function get score():Number
		{
			return Number(this.txtScore.text.substr(6));
		}
		
		public function set speed(num:Number):void
		{
			num = (num < 0) ? 0 : num;
			this.txtSpeed.text = "Speed:" + num;
		}
		
		public function get speed():Number
		{
			return Number(this.txtScore.text.substr(6));
		}
		
		public function set line(num:Number):void
		{
			num = (num < 0) ? 0 : num;
			this.txtLine.text = "Clean:" + num;
		}
		
		public function get line():Number
		{
			return Number(this.txtLine.text.substr(6));
		}		
	}
}